﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;


namespace QLKN.DataAccess
{
    class Data
    {
        public static SqlConnection getConnection()
        {
            SqlConnection conn = null;
            string strconn = @"Data Source=.; Initial Catalog=Qlgiaiquyetkhieunai; Uid=sa; pwd=sa";
            try
            {
                conn = new SqlConnection(strconn);

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return conn;
       
        }
        public static DataTable getDataTable(string sql,SqlConnection conn)
        {
            SqlCommand cmd=new SqlCommand(sql,conn);
            SqlDataAdapter da=new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds.Tables[0];

        }
        public static DataTable Taobang(string tablename,SqlConnection conn)
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM"+tablename, conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds.Tables[0];

        }


    
    }
}
